/*
  Created on Jul 6, 2005
  (C) 2005 
  @author Michael Long, Adam D. Bradley

  This program is free software; you can redistribute it and/or
  modify it under the terms of Version 2 of the GNU General Public 
  License.
  
  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  General Public License for more details.
  
  You should have received a copy of the GNU Library General Public
  License along with this library; if not, write to the Free
  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

package snobject;

import org.w3c.dom.*;

import snbenchlib.Util;
import snobject.snObject;

public class snBoolean extends snObject {

	/**
	 * instantiate a new snBoolean with given content
	 * @param _content
	 */
	public snBoolean(Boolean _content) {
		super();
		
		this.content = _content;
	}

	public String getXmlMimeType() { return MimeTypes.BOOLEAN; }
	public String getWebMimeType() { return "text/plain"; }
	public String getBinaryMimeType() { return "application/binary"; }
		
	public Boolean getBoolean(){
		return (Boolean)this.content;
	}
	
	public void xmlWrite(java.io.OutputStream out, int depth) throws java.io.IOException {
		xmlWritePre(out,depth);
		out.write(( 
			   (((Boolean)this.content).booleanValue()?"true":"false")
			   ).getBytes());
		xmlWritePost(out,0);
	}
	public void webWrite(java.io.OutputStream out, int depth) throws java.io.IOException {
		step.Node.Indent(out, depth);
		out.write((((Boolean)this.content).booleanValue()?"true":"false").getBytes());
	}
	public void binaryWrite(java.io.OutputStream out) throws java.io.IOException {
		out.write(((Boolean)this.content).booleanValue()?1:0);
	}
	public static snObject TRUE = new snBoolean(new java.lang.Boolean(true));
	public static snObject FALSE = new snBoolean(new java.lang.Boolean(false));

	public static snBoolean xmlParse(Element e) {
		if (!e.getTagName().equals("snobject"))
			return null;
		Node n = e.getFirstChild();
		do {
			if (n.getNodeType() == Node.TEXT_NODE) {
				Text ee = (Text) n;
				if (ee.getData().equals("true"))
					return new snBoolean(new Boolean(true));
				if (ee.getData().equals("false"))
					return new snBoolean(new Boolean(false));
			}
		} while ((n = n.getNextSibling()) != null);
		return null;
	}
}
